home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / sc6.8 / part03 < prev    next >
Encoding:
Internet Message Format  |  1990-10-09  |  53.5 KB

  1. Subject:  v23i023:  The SC Spreadsheet, release 6.8, Part03/06
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: c59bf4b8 09be2f0a e33025a6 12876654
  5.  
  6. Submitted-by: Jeff Buhrt <sawmill!buhrt>
  7. Posting-number: Volume 23, Issue 23
  8. Archive-name: sc6.8/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  help.c sc.c
  17. # Wrapped by rsalz@litchi.bbn.com on Fri Jul 13 15:24:19 1990
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. echo If this archive is complete, you will see the following message:
  20. echo '          "shar: End of archive 3 (of 6)."'
  21. if test -f 'help.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'help.c'\"
  23. else
  24.   echo shar: Extracting \"'help.c'\" \(16990 characters\)
  25.   sed "s/^X//" >'help.c' <<'END_OF_FILE'
  26. X/*
  27. X * Help functions for sc 
  28. X * R. Bond, 1988
  29. X * $Revision: 6.8 $
  30. X */
  31. X
  32. X#include <curses.h>
  33. X#include "sc.h"
  34. X
  35. Xchar *intro[] = {
  36. X" ",
  37. X" Overview:",
  38. X" ",
  39. X" A:   This overview",
  40. X" B:   Options",
  41. X" C:   Cursor movement commands",
  42. X" D:   Cell entry and editing commands",
  43. X" E:   Line Editing",
  44. X" F:   File commands",
  45. X" G:   Row and column commands",
  46. X" H:   Range commands",
  47. X" I:   Miscellaneous commands",
  48. X" J:   Variable names/Expressions",
  49. X" K:   Range functions",
  50. X" L:   Numeric functions",
  51. X" M:   String functions",
  52. X" N:   Financial functions",
  53. X" O:   Time and date functions",
  54. X" ",
  55. X" Q:   Return to main spreadsheet",
  56. X(char *)0
  57. X};
  58. X
  59. Xchar *options[] = {
  60. X" ",
  61. X" B: Options",
  62. X" ",
  63. X"     ^To  Toggle options. Toggle one option selected by o:",
  64. X" ",
  65. X"          a    Recalculate automatically or on ``@'' commands.",
  66. X"          c    Current cell highlighting enable/disable.",  
  67. X"          e    External function execution enable/disable.",
  68. X"          n    If enabled, a digit starts a numeric value.",
  69. X"          t    Top line display enable/disable.",
  70. X"          x    Encrypt/decrypt database and listing files.",
  71. X"          $    Dollar prescale.  If enabled, all numeric constants.",
  72. X"               (not expressions) entered are multipled by 0.01.",
  73. X" ",
  74. X"     S    Set options.  Options include:",
  75. X" ",
  76. X"          byrows        Recalculate in row order. (default)",
  77. X"          bycols        Recalculate in column order.",
  78. X"          iterations=n  Set the number of iterations allowed. (10)",
  79. X"          tblstyle=xx   Set ``T'' output style to:",
  80. X"                        0 (none), tex, latex, or tbl.",
  81. X(char *)0
  82. X};
  83. X
  84. Xchar *cursor[] = {
  85. X" ",
  86. X" C: Cell cursor movement (always OK):",
  87. X" ",
  88. X"     ^N ^P ^B ^F Down, up, back, forward",
  89. X"     ^Ed         Go to end of range.  Follow ^E by a direction indicator",
  90. X"                 such as ^P or j.",
  91. X"     Arrow keys (if the terminal and termcap support them.)",
  92. X" ",
  93. X" Cell cursor movement if no prompt active:",
  94. X"     j,k,l,h    Down, up, right, left",
  95. X"     SPACE      Forward",
  96. X"     ^H         Back",
  97. X"     TAB        Forward, otherwise starts/ends a range",
  98. X"     ^          Up to row 0 of the current column.",
  99. X"     #          Down to the last valid row of the current column.",
  100. X"     0          Back to column A.  Preface with ^U if numeric mode.",
  101. X"     $          Forward to the last valid column of the current row.",
  102. X"     b          Back then up to the previous valid cell.",
  103. X"     w          Forward then down to the next valid cell.",
  104. X"     g          Go to a cell.  Cell name, range name, quoted string,",
  105. X"                or a number specify which cell.",
  106. X(char *)0
  107. X};
  108. X
  109. X
  110. Xchar *cell[] = {
  111. X" ",
  112. X" D: Cell entry and editing commands:",
  113. X" ",
  114. X"     =    Enter a numeric constant or expression.",
  115. X"     <    Enter a left justified string or string expression.",
  116. X"     \",>  Enter a right justified string or string expression.",
  117. X"     e    Edit the current cell's numeric value.",
  118. X"     E    Edit the current cell's string part.",
  119. X"     x    Clear the current cell.",
  120. X"     c    Copy the last marked cell to the current cell.",
  121. X"     m    Mark a cell to be used as the source for ``c''",
  122. X"     +    Increment numeric part",
  123. X"     -    Decrement numeric part",
  124. X" ",
  125. X"     In numeric mode, a decimal digit, ``+'', ``-'', and ``.'' all start",
  126. X"     a new numeric constant or expression.",
  127. X(char *)0
  128. X};
  129. X
  130. X
  131. Xchar *vi[] = {
  132. X" ",
  133. X" E: Line Editor",
  134. X" ",
  135. X"     Hitting the ESC key while entering any command on the top line",
  136. X"     will start a one-line vi-style editor.  Supported commands:",
  137. X" ",
  138. X"     ESC q        Abort command entry.",
  139. X"     h l          Move cursor forward, backward.",
  140. X"     0 $          Move cursor to the beginning, end of the line.",
  141. X"     b w          Move cursor forward/back one word.",
  142. X"     fc           Move cursor to character c.",
  143. X"     tc           Move the cursor the the character before c.",
  144. X"     i a          Enter insert mode before/after the cursor.",
  145. X"     I            Move to cursor column 0 and enter insert mode.",
  146. X"     x X          Delete the character under/before the cursor.",
  147. X"     rc           Replace the character under the cursor with c.",
  148. X"     cm           Change - m = b,f,h,l,t or w.",
  149. X"     dm           Delete - m = b,f,h,l,t or w.",
  150. X"     R            Enter replace (overstrike) mode.",
  151. X"     + j - k /    Forward/backward/search the command history.",
  152. X"     n            Repeat last history search.",
  153. X"     . u          Repeat/undo the last command.",
  154. X(char *)0
  155. X};
  156. X
  157. Xchar *file[] = {
  158. X" ",
  159. X" F: File commands:",
  160. X" ",
  161. X"     G    Get a new database from a file. ",
  162. X"     M    Merge a new file into the current database.",
  163. X"     P    Put the current database into a file.",
  164. X"     W    Write a listing of the current database into a file in",
  165. X"          a form that matches its appearance on the screen.",
  166. X"     T    Write a listing of the current database to a file, but",
  167. X"          put delimiters between each pair of fields.",
  168. X"          Optionally brackets output with control lines for ``tbl'',",
  169. X"          ``LaTeX'', or ``TeX''.",
  170. X" ",
  171. X"     If encryption mode is set, file I/O will be encrypted/decrypted.",
  172. X"     ``\"| program\"'' for a file name will pipe (unencrypted) output to",
  173. X"     a program for Put, Write and Table.  If a cell name is used",
  174. X"     as the file name, the cell's string part will be used as the",
  175. X"     file name.",
  176. X(char *)0
  177. X};
  178. X
  179. X
  180. Xchar *row[] = {
  181. X" ",
  182. X" G: Row and column commands:",
  183. X" ",
  184. X"     ir, ic      Insert a new, empty row (column)",
  185. X"     ar, ac      Append a new copy of the current row (column)",
  186. X"     dr, dc      Delete the current row (column)",
  187. X"     pr, pc, pm  Pull deleted cells back into the spreadsheet",
  188. X"                 Insert rows, columns or merge the cells.",
  189. X"     vr, vc      Remove expressions from the affected rows (columns),",
  190. X"                 leaving only the values.",
  191. X"     zr, zc      Hide (``zap'') the current row (column)",
  192. X"     sr, sc      Show hidden rows (columns)",
  193. X"     f           Set the output format to be used with the values of",
  194. X"                 each cell in this column.  Enter field width and",
  195. X"                 number of fractional digits.  A preceding count can be",
  196. X"                 used to change more than one column.",
  197. X" ",
  198. X"     Commands which move or copy cells also modify the row and column ",
  199. X"     references in the new cell expressions.  Use ``fixed'' or the",
  200. X"     ``$'' style cell reference to supress the change.",
  201. X(char *)0
  202. X};
  203. X
  204. X
  205. Xchar *range[] = {
  206. X" ",
  207. X" H: Range commands:",
  208. X" ",
  209. X"     /x   Clear a range. ",
  210. X"     /v   Remove the expressions from a range of cells, leaving ",
  211. X"          just the values.",
  212. X"     /c   Copy a source range to a destination range.",
  213. X"     /f   Fill a range with constant values starting with a given",
  214. X"          value and increasing by a given increment.",
  215. X"     /d   Assign a name to a cell or a range of cells.  Give the",
  216. X"          the name, surrounded by quotes, and either a cell name such",
  217. X"          as ``A10'' or a range such as ``a1:b20''.",
  218. X"     /s   Shows the currently defined range names.  Pipe output to",
  219. X"          sort, then to less.",
  220. X"     /u   Use this command to undefine a previously defined range",
  221. X"          name.",
  222. X" ",
  223. X"     Range operations affect a rectangular region on the screen",
  224. X"     defined by the upper left and lower right cells in the region.",
  225. X"     A range is specified by giving the cell names separated by ``:'',",
  226. X"     such as ``a20:k52''.  Another way to refer to a range is to use",
  227. X"     a name previously defined using ``/d''.",
  228. X(char *)0
  229. X};
  230. X
  231. X
  232. Xchar *misc[] = {
  233. X" ",
  234. X" I: Miscellaneous commands:",
  235. X" ",
  236. X"     Q q ^C   Exit from the program.",
  237. X"     ^G ESC   Abort entry of the current command.",
  238. X"     ?        Help",
  239. X"     !        Shell escape.  Enter a command to run.  ``!!'' repeats",
  240. X"              the last command.  Just ``!'' starts an interactive shell.",
  241. X"     ^L       Redraw the screen.",
  242. X"     ^R       Redraw the screen.  Highlight cells with values but no",
  243. X"              expressions.",
  244. X"     ^X       Redraw the screen.  Show formulas, not values.",
  245. X"     @        Recalculate the spreadsheet.",
  246. X"     ^V       Type, in the command line, the name of the current cell.",
  247. X"     ^W       Type, in the command line, the current cell's expression.",
  248. X"     ^A       Type, in the command line, the current cell's numeric value.",
  249. X"     TAB      When the character cursor is on the top line TAB can be used",
  250. X"              to start or stop the display of the default range.",
  251. X(char *)0
  252. X};
  253. X
  254. Xchar *var[] = {
  255. X" ",
  256. X" J: Variable names:",
  257. X" ",
  258. X"     K20    Row and column can vary on copies.",
  259. X"     $K$20  Row and column stay fixed on copies.",
  260. X"     $K20   Row can vary; column stays fixed on copies.",
  261. X"     K$20   Row stays fixed; column can vary on copies.",
  262. X"     fixed  holds following expession fixed on copies.",
  263. X"     Cells and ranges can be given a symbolic name via ``/d''.",
  264. X" ",
  265. X" Expressions:",
  266. X"     -e      Negation                e<=e  Less than or equal",
  267. X"     e+e     Addition                e=e   Equal",
  268. X"     e-e     Subtraction             e!=e  Not Equal",
  269. X"     e*e     Multiplication          e>=e  Greater than or equal",
  270. X"     e/e     Division                e>e  Greater than",
  271. X"     e%e     Modulo                  e<e  Less than",
  272. X"     e^e     Exponentiation          e&e  Boolean operator AND.",
  273. X"     ~e      Boolean operator NOT    e|e  Boolean operator OR",
  274. X"     e?e1:e2  or @if(e,e1,e2)",
  275. X"             Conditional: If e is non zero then then e1, else e2.",
  276. X"     Terms may be constants, variables, and parenthesized expressions.",
  277. X(char *)0
  278. X};
  279. X
  280. Xchar *rangef[] = {
  281. X" ",
  282. X" K: Range functions:",
  283. X" ",
  284. X"     @sum(r)           Sum all valid cells in the range.",
  285. X"     @prod(r)          Multiply together all valid cells in the range.",
  286. X"     @avg(r)           Average all valid cells in the range.",
  287. X"     @count(r)         Count all valid cells in the range.",
  288. X"     @max(r)           Return the maximum value in the range.",
  289. X"     @min(r)           Return the minimum value in the range.",
  290. X"     @stddev(r)        Return the sample standard deviation of ",
  291. X"                       the cells in the range.",
  292. X"     @index(e,r) @stindex(e,r)",
  293. X"                       Return the numeric (string) value of the cell at",
  294. X"                       index e into range r.",
  295. X"     @lookup(e,r) @hlookup(e,r,n) @vlookup(e,r,n)",
  296. X"                       Search through the range r for a value that",
  297. X"                       matches e.  If e is numeric, the last value <= e",
  298. X"                       matches; if string, an exact match is required.",
  299. X"                       @lookup searches a single row (column) and returns",
  300. X"                       the value from the next column (row); @hlookup",
  301. X"                       (@vlookup) searches the first row (column) in r and",
  302. X"                       returns the value n columns (rows) from the match.",
  303. X(char *)0
  304. X};
  305. X
  306. Xchar *numericf[] = {
  307. X" ",
  308. X" L: Numeric functions:",
  309. X" ",
  310. X"     @atan2(e1,e2)     Arc tangent of e1/e2.",
  311. X"     @ceil(e)          Smallest integer not less than e.",
  312. X"     @eqs(se1,se2)     1 if string expr se1 has the same value as se2.",
  313. X"     @exp(e)           Exponential function of e.",
  314. X"     @abs(e) @fabs(e)  Absolute value of e.",
  315. X"     @floor(e)         The largest integer not greater than e.",
  316. X"     @hypot(x,y)       Sqrt(x*x+y*y).",
  317. X"     @max(e1,e2,...)   The maximum of the values of the e's.",
  318. X"     @min(e1,e2,...)   The minimum of the values of the e's",
  319. X"     @nval(se,e)       The numeric value of a named cell.",
  320. X"     pi                A constant quite close to pi.",
  321. X"     @pow(e1,e2)       e1 raised to the power of e2.",
  322. X"     @rnd(e)           Round e to the nearest integer.",
  323. X"     @round(e,n)       Round e to n decimal places.",
  324. X"     @sqrt(e)          Square root of e.",
  325. X"     @ston(se)         Convert string expr se to a numeric",
  326. X"     @ln(e)   @log(e)           Natural/base 10 logarithm of e.",
  327. X"     @dtr(e)  @rtd(e)           Convert degrees to/from radians.",
  328. X"     @cos(e)  @sin(e)  @tan(e)  Trig functions of radian arguments.",
  329. X"     @asin(e) @acos(e) @atan(e) Inverse trig function.",
  330. X(char *)0
  331. X};
  332. X
  333. Xchar *stringf[] = {
  334. X" ",
  335. X" M: String functions:",
  336. X" ",
  337. X"     #                 Concatenate strings.  For example, the",
  338. X"                       string expression ``A0 # \"zy dog\"'' yields",
  339. X"                       ``the lazy dog'' if A0 is ``the la''.",
  340. X"     @substr(se,e1,e2) Extract characters e1 through e2 from the",
  341. X"                       string expression se.  For example,",
  342. X"                       ``@substr(\"Nice jacket\" 4, 7)'' yields ",
  343. X"                       ``e jac''.",
  344. X"     @fmt(se,e)        Convert a number to a string using sprintf(3).",
  345. X"                       For example,  ``@fmt(\"*%6.3f*\",10.5)'' yields",
  346. X"                       ``*10.500*''.  Use formats are e, E, f, g, and G.", 
  347. X"     @sval(se,e)       Return the string value of a cell selected by name.",
  348. X"     @ext(se,e)        Call an external function (program or",
  349. X"                       script).  Convert e to a string and append it",
  350. X"                       to the command line as an argument.  @ext yields",
  351. X"                       a string: the first line printed to standard",
  352. X"                       output by the command.",
  353. X"     String expressions are made up of constant strings (characters",
  354. X"     surrounded by quotes), variables, and string functions.",
  355. X(char *)0
  356. X};
  357. X
  358. X
  359. Xchar *finf[] = {
  360. X" ",
  361. X" N: Financial functions:",
  362. X" ",
  363. X"     @pmt(e1,e2,e3)    @pmt(60000,.01,360) computes the monthly",
  364. X"                       payments for a $60000 mortgage at 12%",
  365. X"                       annual interest (.01 per month) for 30",
  366. X"                       years (360 months).",
  367. X" ",
  368. X"     @fv(e1,e2,e3)     @fv(100,.005,36) computes the future value",
  369. X"                       of 36 monthly payments of $100 at 6%",
  370. X"                       interest (.005 per month).  It answers the",
  371. X"                       question:  ``How much will I have in 36",
  372. X"                       months if I deposit $100 per month in a",
  373. X"                       savings account paying 6% interest com-",
  374. X"                       pounded monthly?''",
  375. X" ",
  376. X"     @pv(e1,e2,e3)     @pv(1000,.015,36) computes the present",
  377. X"                       value of an ordinary annuity of 36",
  378. X"                       monthly payments of $1000 at 18% annual",
  379. X"                       interest.  It answers the question: ``How",
  380. X"                       much can I borrow at 18% for 30 years if I",
  381. X"                       pay $1000 per month?''",
  382. X(char *)0
  383. X};
  384. X
  385. X
  386. Xchar *timef[] = {
  387. X" ",
  388. X" O: Time and date functions:",
  389. X" ",
  390. X"     @now              Return the time encoded in seconds since 1970.",
  391. X"     @dts(m,d,y)       Return m/d/y encoded in seconds since 1970.",
  392. X"     @tts(h,m,s)       Return h:m:s encoded in seconds since midnight.",
  393. X" ",
  394. X"     All of the following take an argument expressed in seconds:",
  395. X" ",
  396. X"     @date(e)          Convert the time in seconds to a date",
  397. X"                       string 24 characters long in the following",
  398. X"                       form: ``Sun Sep 16 01:03:52 1973''.  Note",
  399. X"                       that you can extract pieces of this fixed format",
  400. X"                       string with @substr.",
  401. X"     @year(e)          Return the year.  Valid years begin with 1970.",
  402. X"     @month(e)         Return the month: 1 (Jan) to 12 (Dec).",
  403. X"     @day(e)           Return the day of the month: 1 to 31.",
  404. X"     @hour(e)          Return the number of hours since midnight: 0 to 23.",
  405. X"     @minute(e)        Return the number of minutes since the",
  406. X"                       last full hour: 0 to 59.",
  407. X"     @second(e)        Return the number of seconds since the",
  408. X"                       last full minute: 0 to 59.",
  409. X(char *)0
  410. X};
  411. Xvoid
  412. Xhelp()
  413. X{
  414. X    int option;
  415. X    char **ns = intro;
  416. X
  417. X    while((option = pscreen(ns)) != 'q' && option != 'Q') {
  418. X        switch (option) {
  419. X    case 'a': case 'A': ns = intro; break;
  420. X    case 'b': case 'B': ns = options; break;
  421. X    case 'c': case 'C': ns = cursor; break;
  422. X    case 'd': case 'D': ns = cell; break;
  423. X    case 'e': case 'E': ns = vi; break;
  424. X    case 'f': case 'F': ns = file; break;
  425. X    case 'g': case 'G': ns = row; break;
  426. X    case 'h': case 'H': ns = range; break;
  427. X    case 'i': case 'I': ns = misc; break;
  428. X    case 'j': case 'J': ns = var; break;
  429. X    case 'k': case 'K': ns = rangef; break;
  430. X    case 'l': case 'L': ns = numericf; break;
  431. X    case 'm': case 'M': ns = stringf; break;
  432. X    case 'n': case 'N': ns = finf; break;
  433. X    case 'o': case 'O': ns = timef; break;
  434. X    default: ns = intro; break;
  435. X    }
  436. X    }
  437. X    FullUpdate++;
  438. X    (void) move(1,0);
  439. X    (void) clrtobot();
  440. X}
  441. X
  442. Xpscreen(screen)
  443. Xchar *screen[];
  444. X{
  445. X    int line;
  446. X    int dbline;
  447. X
  448. X    (void) move(1,0);
  449. X    (void) clrtobot();
  450. X    dbline = 1;
  451. X    for (line = 0; screen[line]; line++) {
  452. X    (void) move(dbline++, 4);
  453. X    (void) addstr (screen[line]);
  454. X    (void) clrtoeol();
  455. X    }
  456. X    (void) move(0,0);
  457. X    (void) printw("Which Screen? [a-n, q]");
  458. X    (void) clrtoeol();
  459. X    (void) refresh();
  460. X    return(nmgetch());
  461. X}
  462. END_OF_FILE
  463.   if test 16990 -ne `wc -c <'help.c'`; then
  464.     echo shar: \"'help.c'\" unpacked with wrong size!
  465.   fi
  466.   # end of 'help.c'
  467. fi
  468. if test -f 'sc.c' -a "${1}" != "-c" ; then 
  469.   echo shar: Will not clobber existing file \"'sc.c'\"
  470. else
  471.   echo shar: Extracting \"'sc.c'\" \(33828 characters\)
  472.   sed "s/^X//" >'sc.c' <<'END_OF_FILE'
  473. X/*    SC    A Spreadsheet Calculator
  474. X *        Main driver
  475. X *
  476. X *        original by James Gosling, September 1982
  477. X *        modifications by Mark Weiser and Bruce Israel,
  478. X *            University of Maryland
  479. X *
  480. X *              More mods Robert Bond, 12/86
  481. X *        More mods by Alan Silverstein, 3-4/88, see list of changes.
  482. X *        Currently supported by pur-phy!sawmill!buhrt (Jeff Buhrt)
  483. X *        $Revision: 6.8 $
  484. X *
  485. X */
  486. X
  487. X
  488. X#include <signal.h>
  489. X#include <curses.h>
  490. X#include <ctype.h>
  491. X
  492. X#ifdef BSD42
  493. X#include <strings.h>
  494. X#else
  495. X#ifndef SYSIII
  496. X#include <string.h>
  497. X#endif
  498. X#endif
  499. X
  500. X#include <stdio.h>
  501. X#include "sc.h"
  502. X
  503. Xchar *getenv();
  504. X
  505. X#ifdef SYSV3
  506. Xvoid exit();
  507. X#endif
  508. X
  509. X#ifndef DFLT_PAGER
  510. X#define    DFLT_PAGER "more"    /* more is probably more widespread than less */
  511. X#endif /* DFLT_PAGER */
  512. X
  513. X#define MAXCMD 160    /* for ! command below */
  514. X
  515. Xextern    char    *rev;
  516. X
  517. X/* Globals defined in sc.h */
  518. X
  519. Xstruct ent ***tbl;
  520. Xint strow, stcol;
  521. Xint currow, curcol;
  522. Xint savedrow, savedcol;
  523. Xint FullUpdate;
  524. Xint maxrow, maxcol;
  525. Xint maxrows, maxcols;
  526. Xint *fwidth;
  527. Xint *precision;
  528. Xchar *col_hidden;
  529. Xchar *row_hidden;
  530. Xchar line[FBUFLEN];
  531. Xint changed;
  532. Xstruct ent *to_fix;
  533. Xint modflg;
  534. Xint numeric;
  535. Xchar *mdir;
  536. Xint showsc, showsr;    /* Starting cell for highlighted range */
  537. Xchar mode_ind = '.';
  538. X
  539. Xchar curfile[PATHLEN];
  540. Xchar    revmsg[80];
  541. X
  542. Xint  linelim = -1;
  543. X
  544. Xint  showtop   = 1;    /* Causes current cell value display in top line  */
  545. Xint  showcell  = 1;    /* Causes current cell to be highlighted      */
  546. Xint  showrange = 0;    /* Causes ranges to be highlighted          */
  547. Xint  showneed  = 0;    /* Causes cells needing values to be highlighted  */
  548. Xint  showexpr  = 0;    /* Causes cell exprs to be displayed, highlighted */
  549. X
  550. Xint  autocalc = 1 ;    /* 1 to calculate after each update */
  551. Xint  calc_order = BYROWS;
  552. Xint  tbl_style = 0;    /* headers for T command output */
  553. X
  554. Xint  lastmx, lastmy;    /* Screen address of the cursor */
  555. Xint  lastcol;        /* Spreadsheet Column the cursor was in last */
  556. Xchar under_cursor[] = " "; /* Data under the < cursor */
  557. X
  558. X#ifdef VMS
  559. Xint VMS_read_raw = 0;
  560. X#endif
  561. X
  562. Xint seenerr;
  563. X
  564. Xvoid
  565. Xyyerror(err)
  566. Xchar *err; {
  567. X    if (seenerr) return;
  568. X    seenerr++;
  569. X    (void) move(1,0);
  570. X    (void) clrtoeol();
  571. X    (void) printw("%s: %.*s<=%s",err,linelim,line,line+linelim);
  572. X}
  573. X
  574. Xstruct ent *
  575. Xlookat(row,col)
  576. Xint    row, col;
  577. X{
  578. X    register struct ent **pp;
  579. X
  580. X    checkbounds(&row, &col);
  581. X    pp = ATBL(tbl, row, col);
  582. X    if (*pp == (struct ent *)0) {
  583. X    *pp = (struct ent *) xmalloc((unsigned)sizeof(struct ent));
  584. X    if (row>maxrow) maxrow = row;
  585. X    if (col>maxcol) maxcol = col;
  586. X    (*pp)->label = (char *)0;
  587. X    (*pp)->row = row;
  588. X    (*pp)->col = col;
  589. X    (*pp)->flags = 0;
  590. X    (*pp)->expr = (struct enode *)0;
  591. X    (*pp)->v = (double) 0.0;
  592. X    (*pp)->evnext = (struct ent *)0;
  593. X    }
  594. X    return *pp;
  595. X}
  596. X
  597. X/*
  598. X * This structure is used to keep ent structs around before they
  599. X * are deleted to allow the sync_refs routine a chance to fix the
  600. X * variable references.
  601. X * We also use it as a last-deleted buffer for the 'p' command.
  602. X */
  603. X
  604. Xvoid
  605. Xfree_ent(p)
  606. Xregister struct ent *p;
  607. X{
  608. X    p->next = to_fix;
  609. X    to_fix = p;
  610. X    p->flags |= is_deleted;
  611. X}
  612. X
  613. Xvoid
  614. Xflush_saved()
  615. X{
  616. X    register struct ent *p;
  617. X    register struct ent *q;
  618. X
  619. X    if (!(p = to_fix))
  620. X    return;
  621. X    while (p) {
  622. X    (void) clearent(p);
  623. X    q = p->next;
  624. X    xfree((char *)p);
  625. X    p = q;
  626. X    }
  627. X    to_fix = 0;
  628. X}
  629. X
  630. X/*
  631. X * standout last time in update()?
  632. X *    At this point we will let curses do work
  633. X */
  634. Xint    standlast    = FALSE;
  635. X
  636. Xvoid
  637. Xupdate (anychanged)
  638. Xint    anychanged;    /* did any cell really change in value? */
  639. X{
  640. X    register    row,
  641. X                col;
  642. X    register struct ent **pp;
  643. X    int     mxcol;
  644. X    int     mxrow;
  645. X    int     rows;
  646. X    int     cols;
  647. X    int     minsr, minsc, maxsr, maxsc;
  648. X    register r;
  649. X    register i;
  650. X
  651. X    while (row_hidden[currow])   /* You can't hide the last row or col */
  652. X    currow++;
  653. X    while (col_hidden[curcol])
  654. X    curcol++;
  655. X    /* First see if the last display still covers curcol */
  656. X    if (stcol <= curcol) { 
  657. X    for (i = stcol, cols = 0, col = RESCOL;
  658. X            (col + fwidth[i]) < COLS-1 && i < maxcols; i++) {
  659. X        cols++;
  660. X        if (col_hidden[i])
  661. X        continue;
  662. X        col += fwidth[i];
  663. X    }
  664. X    }
  665. X    while (stcol + cols - 1 < curcol || curcol < stcol) {
  666. X    FullUpdate++;
  667. X    if (stcol - 1 == curcol) {    /* How about back one? */
  668. X        stcol--;
  669. X    } else if (stcol + cols == curcol) {   /* Forward one? */
  670. X        stcol++;
  671. X    } else {
  672. X        /* Try to put the cursor in the center of the screen */
  673. X        col = (COLS - RESCOL - fwidth[curcol]) / 2 + RESCOL; 
  674. X        stcol = curcol;
  675. X        for (i=curcol-1; i >= 0 && col-fwidth[i] > RESCOL; i--) {
  676. X        stcol--;
  677. X        if (col_hidden[i])
  678. X            continue;
  679. X        col -= fwidth[i];
  680. X        }
  681. X    }
  682. X    /* Now pick up the counts again */
  683. X    for (i = stcol, cols = 0, col = RESCOL;
  684. X            (col + fwidth[i]) < COLS-1 && i < maxcols; i++) {
  685. X        cols++;
  686. X        if (col_hidden[i])
  687. X        continue;
  688. X        col += fwidth[i];
  689. X    }
  690. X    }
  691. X    /* Now - same process on the rows */
  692. X    if (strow <= currow) { 
  693. X    for (i = strow, rows = 0, row=RESROW; row<LINES && i<maxrows; i++) {
  694. X        rows++;
  695. X        if (row_hidden[i])
  696. X        continue;
  697. X        row++;
  698. X    }
  699. X    }
  700. X    while (strow + rows - 1 < currow || currow < strow) {
  701. X    FullUpdate++;
  702. X    if (strow - 1 == currow) {    /* How about up one? */
  703. X        strow--;
  704. X    } else if (strow + rows == currow) {   /* Down one? */
  705. X        strow++;
  706. X    } else {
  707. X        /* Try to put the cursor in the center of the screen */
  708. X        row = (LINES - RESROW) / 2 + RESROW; 
  709. X        strow = currow;
  710. X        for (i=currow-1; i >= 0 && row-1 > RESROW; i--) {
  711. X        strow--;
  712. X        if (row_hidden[i])
  713. X            continue;
  714. X        row--;
  715. X        }
  716. X    }
  717. X    /* Now pick up the counts again */
  718. X    for (i = strow, rows = 0, row=RESROW; row<LINES && i<maxrows; i++) {
  719. X        rows++;
  720. X        if (row_hidden[i])
  721. X        continue;
  722. X        row++;
  723. X    }
  724. X    }
  725. X    mxcol = stcol + cols - 1;
  726. X    mxrow = strow + rows - 1;
  727. X    if (FullUpdate || standlast) {
  728. X    (void) move(2, 0);
  729. X    (void) clrtobot();
  730. X    (void) standout();
  731. X    for (row=RESROW, i=strow; i <= mxrow; i++) {
  732. X        if (row_hidden[i]) 
  733. X        continue;
  734. X        (void) move(row,0);
  735. X        if (maxrows < 1000)
  736. X        (void) printw("%-*d", RESCOL-1, i);
  737. X        else
  738. X        (void) printw("%-*d", RESCOL, i);
  739. X        row++;
  740. X    }
  741. X    (void) move(2,0);
  742. X    (void) printw("%*s", RESCOL, " ");
  743. X
  744. X    for (col=RESCOL, i = stcol; i <= mxcol; i++) {
  745. X        register int k;
  746. X        if (col_hidden[i])
  747. X        continue;
  748. X        (void) move(2, col);
  749. X        k = fwidth[i]/2;
  750. X        if (k == 0)
  751. X        (void) printw("%1s", coltoa(i));
  752. X        else
  753. X            (void) printw("%*s%-*s", k, " ", fwidth[i]-k, coltoa(i));
  754. X        col += fwidth[i];
  755. X    }
  756. X    (void) standend();
  757. X    }
  758. X
  759. X    /* Get rid of cursor standout on the cell at previous cursor position */
  760. X    if (showcell)
  761. X    {    (void) move(lastmx, lastmy);
  762. X        repaint(lastmx, lastmy, fwidth[lastcol]);
  763. X    }
  764. X
  765. X    if (showrange) {
  766. X    minsr = showsr < currow ? showsr : currow;
  767. X    minsc = showsc < curcol ? showsc : curcol;
  768. X    maxsr = showsr > currow ? showsr : currow;
  769. X    maxsc = showsc > curcol ? showsc : curcol;
  770. X
  771. X    if (showtop) {
  772. X        (void) move(1,0);
  773. X        (void) clrtoeol();
  774. X        (void) printw("Default range:  %s",
  775. X                r_name(minsr, minsc, maxsr, maxsc));
  776. X    }
  777. X    }
  778. X
  779. X    /* Repaint the visible screen */
  780. X    if (showrange || anychanged || FullUpdate || standlast)
  781. X    {
  782. X    /* may be reset in loop, if not next time we will do a FullUpdate */
  783. X      if (standlast)
  784. X      {    FullUpdate = TRUE;
  785. X    standlast = FALSE;
  786. X      }
  787. X      for (row = strow, r = RESROW; row <= mxrow; row++) {
  788. X    register c = RESCOL;
  789. X    int do_stand = 0;
  790. X    int fieldlen;
  791. X    int nextcol;
  792. X
  793. X    if (row_hidden[row])
  794. X        continue;
  795. X    for (pp = ATBL(tbl, row, col = stcol); col <= mxcol;
  796. X             pp += nextcol - col,  col = nextcol, c += fieldlen) {
  797. X
  798. X        nextcol = col+1;
  799. X        if (col_hidden[col]) {
  800. X        fieldlen = 0;
  801. X        continue;
  802. X        }
  803. X
  804. X        fieldlen = fwidth[col];
  805. X
  806. X        /*
  807. X         * Set standout if:
  808. X         *
  809. X         * - showing ranges, and not showing cells which need to be filled
  810. X         *     in, and not showing cell expressions, and in a range, OR
  811. X         *
  812. X         * - if showing cells which need to be filled in and this one is
  813. X         *     of that type (has a value and doesn't have an expression,
  814. X         *     or it is a string expression), OR
  815. X         *
  816. X         * - if showing cells which have expressions and this one does.
  817. X         */
  818. X
  819. X        if ((showrange && (! showneed) && (! showexpr)
  820. X               && (row >= minsr) && (row <= maxsr)
  821. X               && (col >= minsc) && (col <= maxsc))
  822. X            || (showneed && (*pp) && ((*pp) -> flags & is_valid)
  823. X            && (((*pp) -> flags & is_strexpr) || !((*pp) -> expr)))
  824. X            || (showexpr && (*pp) && ((*pp) -> expr)))
  825. X        {
  826. X        (void) move(r, c);
  827. X        (void) standout();
  828. X        standlast++;
  829. X        if (!*pp)    /* no cell, but standing out */
  830. X        {    (void) printw("%*s", fwidth[col], " ");
  831. X            (void) standend();
  832. X            continue;
  833. X        }
  834. X        else
  835. X            do_stand = 1;
  836. X        }
  837. X        else
  838. X        do_stand = 0;
  839. X
  840. X        if ((*pp) && ((*pp) -> flags & is_changed || FullUpdate) || do_stand) {
  841. X        if (do_stand) {
  842. X            (*pp) -> flags |= is_changed; 
  843. X        } else {
  844. X            (void) move(r, c);
  845. X            (*pp) -> flags &= ~is_changed;
  846. X        }
  847. X
  848. X        /*
  849. X         * Show expression; takes priority over other displays:
  850. X         */
  851. X
  852. X        if (showexpr && ((*pp) -> expr)) {
  853. X            linelim = 0;
  854. X            editexp(row, col);        /* set line to expr */
  855. X            linelim = -1;
  856. X            showstring(line, /* leftflush = */ 1, /* hasvalue = */ 0,
  857. X                row, col, & nextcol, mxcol, & fieldlen, r, c);
  858. X        }
  859. X        else {
  860. X
  861. X            /*
  862. X             * Show cell's numeric value:
  863. X             */
  864. X
  865. X            if ((*pp) -> flags & is_valid) {
  866. X            char field[FBUFLEN];
  867. X            (void)sprintf(field,"%*.*f", fwidth[col], precision[col], (*pp)->v);
  868. X            if(strlen(field) > fwidth[col]) {
  869. X                for(i = 0; i<fwidth[col]; i++)
  870. X                (void)addch('*');
  871. X            } else {
  872. X                (void)addstr(field);
  873. X            }
  874. X            }
  875. X
  876. X            /*
  877. X             * Show cell's label string:
  878. X             */
  879. X
  880. X            if ((*pp) -> label) {
  881. X            showstring((*pp) -> label,
  882. X                    (*pp) -> flags & is_leftflush,
  883. X                    (*pp) -> flags & is_valid,
  884. X                    row, col, & nextcol, mxcol,
  885. X                    & fieldlen, r, c);
  886. X            }
  887. X            else    /* repaint a blank cell: */
  888. X            if ((do_stand || !FullUpdate) &&
  889. X                ((*pp)->flags & is_changed) &&
  890. X                !((*pp)->flags & is_valid) && !(*pp)->label) {
  891. X            (void) printw("%*s", fwidth[col], " ");
  892. X            }
  893. X        } /* else */
  894. X
  895. X        if (do_stand) {
  896. X            (void) standend();
  897. X            do_stand = 0;
  898. X        }
  899. X        }
  900. X    }
  901. X    r++;
  902. X      }
  903. X    }
  904. X        
  905. X    (void) move(lastmy, lastmx+fwidth[lastcol]);
  906. X    if((inch() & A_CHARTEXT ) == '<')
  907. X        (void) addstr(under_cursor);
  908. X
  909. X    lastmy =  RESROW;
  910. X    for (row = strow; row < currow; row++)
  911. X    if (!row_hidden[row])
  912. X        lastmy += 1;
  913. X    lastmx = RESCOL;
  914. X    for (col = stcol; col < curcol; col++)
  915. X    if (!col_hidden[col])
  916. X        lastmx += fwidth[col];
  917. X    lastcol = curcol;
  918. X    if (showcell && (! showneed) && (! showexpr)) {
  919. X    (void) move(lastmy, lastmx);
  920. X        (void) standout();
  921. X        repaint(lastmx, lastmy, fwidth[lastcol]);
  922. X        (void) standend();
  923. X    }
  924. X    (void) move(lastmy, lastmx+fwidth[lastcol]);
  925. X    *under_cursor = (inch() & A_CHARTEXT );
  926. X    (void) addstr("<");
  927. X
  928. X    (void) move(0, 0);
  929. X    (void) clrtoeol();
  930. X    if (linelim >= 0) {
  931. X    (void) addch(mode_ind);
  932. X    (void) addstr("> ");
  933. X    (void) addstr(line);
  934. X    (void) move(0, linelim+3);
  935. X    } else {
  936. X    if (showtop) {            /* show top line */
  937. X        register struct ent *p1;
  938. X        int printed = 0;        /* printed something? */
  939. X
  940. X            (void) printw("%s%d ", coltoa(curcol), currow);
  941. X
  942. X        if (p1 = *ATBL(tbl, currow, curcol)) {
  943. X        if (p1 -> expr) {
  944. X            /* has expr of some type */
  945. X            linelim = 0;
  946. X            editexp(currow, curcol);    /* set line to expr */
  947. X            linelim = -1;
  948. X        }
  949. X
  950. X        /*
  951. X         * Display string part of cell:
  952. X         */
  953. X
  954. X        if ((p1 -> expr) && (p1 -> flags & is_strexpr)) {
  955. X            (void) addstr((p1 -> flags & is_leftflush) ? "<{" : ">{");
  956. X            (void) addstr(line);
  957. X            (void) addstr("} ");    /* and this '}' is for vi % */
  958. X            printed = 1;
  959. X
  960. X        } else if (p1 -> label) {
  961. X            /* has constant label only */
  962. X            (void) addstr ((p1 -> flags & is_leftflush) ? "<\"" : ">\"");
  963. X            (void) addstr (p1 -> label);
  964. X            (void) addstr ("\" ");
  965. X            printed = 1;
  966. X        }
  967. X
  968. X        /*
  969. X         * Display value part of cell:
  970. X         */
  971. X
  972. X        if (p1 -> flags & is_valid) {
  973. X            /* has value or num expr */
  974. X            if ((! (p1 -> expr)) || (p1 -> flags & is_strexpr))
  975. X            (void) sprintf (line, "%.15g", p1 -> v);
  976. X
  977. X            (void) addstr ("[");
  978. X            (void) addstr (line);
  979. X            (void) addstr ("]");
  980. X            printed = 1;
  981. X        }
  982. X        }
  983. X        if (! printed)
  984. X        (void) addstr ("[]");
  985. X    }
  986. X    (void) move (lastmy, lastmx + fwidth[lastcol]);
  987. X    }
  988. X    if (revmsg[0]) {
  989. X    (void) move(0, 0);
  990. X    (void) clrtoeol ();    /* get rid of topline display */
  991. X    (void) printw(revmsg);
  992. X    revmsg[0] = '\0';    /* don't show it again */
  993. X    (void) move (lastmy, lastmx + fwidth[lastcol]);
  994. X    }
  995. X    FullUpdate = FALSE;
  996. X}
  997. X
  998. Xvoid
  999. Xrepaint(x, y, len)
  1000. Xint x, y, len;
  1001. X{
  1002. X    int c;
  1003. X
  1004. X    while(len-- > 0) {
  1005. X    (void) move(y,x);
  1006. X    c = inch() & A_CHARTEXT;
  1007. X    (void) addch(c);
  1008. X    x++;
  1009. X    }
  1010. X}
  1011. X
  1012. Xchar    *progname;
  1013. X
  1014. Xint
  1015. Xmain (argc, argv)
  1016. Xint argc;
  1017. Xchar  **argv;
  1018. X{
  1019. X    int     inloop = 1;
  1020. X    register int   c;
  1021. X    int     edistate = -1;
  1022. X    int     arg = 1;
  1023. X    int     narg;
  1024. X    int     nedistate;
  1025. X    int        running;
  1026. X    char    *revi;
  1027. X    int        anychanged = FALSE;
  1028. X
  1029. X    /*
  1030. X     * Keep command line options around until the file is read so the
  1031. X     * command line overrides file options
  1032. X     */
  1033. X
  1034. X    int Mopt = 0;
  1035. X    int Nopt = 0;
  1036. X    int Copt = 0; 
  1037. X    int Ropt = 0;
  1038. X
  1039. X    int tempx, tempy;     /* Temp versions of curx, cury */
  1040. X
  1041. X    if ((revi = strrchr(argv[0], '/')) != NULL)
  1042. X    progname = revi+1;
  1043. X    else
  1044. X    progname = argv[0];
  1045. X
  1046. X    while (argc > 1 && argv[1][0] == '-') {
  1047. X    argv++;
  1048. X    argc--;
  1049. X        switch (argv[0][1]) {
  1050. X        case 'x':
  1051. X#ifdef VMS
  1052. X            (void) fprintf(stderr, "Crypt not available for VMS\n");
  1053. X            exit(1);
  1054. X#else 
  1055. X            Crypt = 1;
  1056. X#endif
  1057. X            break;
  1058. X        case 'm':
  1059. X            Mopt = 1;
  1060. X            break;
  1061. X        case 'n':
  1062. X            Nopt = 1;
  1063. X            break;
  1064. X        case 'c':
  1065. X            Copt = 1;
  1066. X            break;
  1067. X        case 'r':
  1068. X            Ropt = 1;
  1069. X            break;
  1070. X        default:
  1071. X            (void) fprintf(stderr,"%s: unrecognized option: \"%c\"\n",
  1072. X            progname,argv[0][1]);
  1073. X            exit(1);
  1074. X    }
  1075. X    }
  1076. X
  1077. X    *curfile ='\0';
  1078. X
  1079. X    signals();
  1080. X    (void) initscr();
  1081. X
  1082. X    /* setup the spreadsheet arrays, initscr() will get the screen size */
  1083. X    if (!growtbl(GROWNEW, 0, 0))
  1084. X    {    endwin();
  1085. X    exit(1);
  1086. X    }
  1087. X
  1088. X    (void) clear();
  1089. X#ifdef VMS
  1090. X    VMS_read_raw = 1;
  1091. X#else
  1092. X    nonl();
  1093. X    noecho ();
  1094. X    cbreak();
  1095. X#endif
  1096. X    initkbd();
  1097. X    scrollok(stdscr, 1);
  1098. X
  1099. X    /*
  1100. X     * Build revision message for later use:
  1101. X     */
  1102. X
  1103. X    (void) strcpy (revmsg, progname);
  1104. X    for (revi = rev; (*revi++) != ':'; );    /* copy after colon */
  1105. X    (void) strcat (revmsg, revi);
  1106. X    revmsg [strlen (revmsg) - 2] = 0;        /* erase last character */
  1107. X    (void) strcat (revmsg, ":  Type '?' for help.");
  1108. X
  1109. X    if (argc > 1) {
  1110. X    (void) strcpy(curfile,argv[1]);
  1111. X    readfile (argv[1], 0);
  1112. X    }
  1113. X
  1114. X    if (Mopt)
  1115. X    autocalc = 0;
  1116. X    if (Nopt)
  1117. X    numeric = 1;
  1118. X    if (Copt)
  1119. X    calc_order = BYCOLS;
  1120. X    if (Ropt)
  1121. X    calc_order = BYROWS;
  1122. X
  1123. X    modflg = 0;
  1124. X#ifdef VENIX
  1125. X    setbuf (stdin, NULL);
  1126. X#endif
  1127. X    FullUpdate++;
  1128. X    while (inloop) { running = 1;
  1129. X    while (running) {
  1130. X    nedistate = -1;
  1131. X    narg = 1;
  1132. X    if (edistate < 0 && linelim < 0 && autocalc && (changed || FullUpdate))
  1133. X    {    EvalAll ();
  1134. X         if (changed)        /* if EvalAll changed or was before */
  1135. X        anychanged = TRUE;
  1136. X         changed = 0;
  1137. X    }
  1138. X    else        /* any cells change? */
  1139. X    if (changed)
  1140. X         anychanged = TRUE;
  1141. X
  1142. X    update(anychanged);
  1143. X    anychanged = FALSE;
  1144. X#ifndef SYSV3
  1145. X    (void) refresh(); /* 5.3 does a refresh in getch */ 
  1146. X#endif
  1147. X    c = nmgetch();
  1148. X    getyx(stdscr, tempy, tempx);
  1149. X    (void) move (1, 0);
  1150. X    (void) clrtoeol ();
  1151. X    (void) move(tempy, tempx);
  1152. X    (void) fflush (stdout);
  1153. X    seenerr = 0;
  1154. X    showneed = 0;    /* reset after each update */
  1155. X    showexpr = 0;
  1156. X
  1157. X    /* if ((c < ' ') || ( c == DEL ))   how about international here ? PB */
  1158. X       if ( iscntrl(c) )
  1159. X        switch (c) {
  1160. X#ifdef SIGTSTP
  1161. X        case ctl('z'):
  1162. X            (void) deraw();
  1163. X            (void) kill(0, SIGTSTP); /* Nail process group */
  1164. X
  1165. X            /* the pc stops here */
  1166. X
  1167. X            (void) goraw();
  1168. X            break;
  1169. X#endif
  1170. X        case ctl('r'):
  1171. X            showneed = 1;
  1172. X        case ctl('l'):
  1173. X            FullUpdate++;
  1174. X            (void) clearok(stdscr,1);
  1175. X            break;
  1176. X        case ctl('x'):
  1177. X            FullUpdate++;
  1178. X            showexpr = 1;
  1179. X            (void) clearok(stdscr,1);
  1180. X            break;
  1181. X        default:
  1182. X            error ("No such command (^%c)", c + 0100);
  1183. X            break;
  1184. X        case ctl('b'):
  1185. X            backcol(arg);
  1186. X            break;
  1187. X        case ctl('c'):
  1188. X            running = 0;
  1189. X            break;
  1190. X
  1191. X        case ctl('e'):
  1192. X
  1193. X            switch (nmgetch()) {
  1194. X            case ctl('p'): case 'k':    doend (-1, 0);    break;
  1195. X            case ctl('n'): case 'j':    doend ( 1, 0);    break;
  1196. X            case ctl('b'): case 'h':
  1197. X            case ctl('h'):        doend ( 0,-1);    break;
  1198. X            case ctl('f'): case 'l':
  1199. X            case ctl('i'): case ' ':    doend ( 0, 1);    break;
  1200. X
  1201. X            case ESC:
  1202. X            case ctl('g'):
  1203. X            break;
  1204. X
  1205. X            default:
  1206. X            error("Invalid ^E command");
  1207. X            break;
  1208. X            }
  1209. X
  1210. X            break;
  1211. X
  1212. X        case ctl('f'):
  1213. X            forwcol(arg);
  1214. X            break;
  1215. X
  1216. X        case ctl('g'):
  1217. X            showrange = 0;
  1218. X            linelim = -1;
  1219. X            (void) move (1, 0);
  1220. X            (void) clrtoeol ();
  1221. X            break;
  1222. X
  1223. X        case ESC:    /* ctl('[') */
  1224. X            write_line(ESC);
  1225. X            break;
  1226. X
  1227. X        case ctl('d'):
  1228. X            write_line(ctl('d'));
  1229. X            break;
  1230. X
  1231. X        case DEL:
  1232. X        case ctl('h'):
  1233. X            if (linelim < 0) {    /* not editing line */
  1234. X            backcol(arg);    /* treat like ^B    */
  1235. X            break;
  1236. X            }
  1237. X            write_line(ctl('h'));
  1238. X            break;
  1239. X
  1240. X        case ctl('i'):         /* tab */
  1241. X            if (linelim < 0) {    /* not editing line */
  1242. X            forwcol(arg);
  1243. X            break;
  1244. X            }
  1245. X            if (!showrange) {
  1246. X            startshow();
  1247. X            } else {
  1248. X            showdr();
  1249. X            linelim = strlen(line);
  1250. X            line[linelim++] = ' ';
  1251. X            line[linelim] = 0;
  1252. X            showrange = 0;
  1253. X            }
  1254. X            linelim = strlen (line);
  1255. X            break;
  1256. X
  1257. X        case ctl('m'):
  1258. X        case ctl('j'):
  1259. X            write_line(ctl('m'));
  1260. X            break;
  1261. X
  1262. X        case ctl('n'):
  1263. X            forwrow(arg);
  1264. X            break;
  1265. X
  1266. X        case ctl('p'):
  1267. X            backrow(arg);
  1268. X            break;
  1269. X
  1270. X        case ctl('q'):
  1271. X            break;    /* ignore flow control */
  1272. X
  1273. X        case ctl('s'):
  1274. X            break;    /* ignore flow control */
  1275. X
  1276. X        case ctl('t'):
  1277. X            error(
  1278. X"Toggle:  a:auto  c:cell  e:ext funcs  n:numeric  t:top  x:encrypt  $:pre-scale");
  1279. X            (void) refresh();
  1280. X
  1281. X            switch (nmgetch()) {
  1282. X            case 'a': case 'A':
  1283. X            case 'm': case 'M':
  1284. X                autocalc ^= 1;
  1285. X                error("Automatic recalculation %sabled.",
  1286. X                autocalc ? "en":"dis");
  1287. X                break;
  1288. X            case 'n': case 'N':
  1289. X                numeric = (! numeric);
  1290. X                error ("Numeric input %sabled.",
  1291. X                    numeric ? "en" : "dis");
  1292. X                break;
  1293. X            case 't': case 'T':
  1294. X                showtop = (! showtop);
  1295. X                repaint(lastmx, lastmy, fwidth[lastcol]);
  1296. X                error ("Top line %sabled.", showtop ? "en" : "dis");
  1297. X                break;
  1298. X            case 'c': case 'C':
  1299. X                showcell = (! showcell);
  1300. X                repaint(lastmx, lastmy, fwidth[lastcol]);
  1301. X                error ("Cell highlighting %sabled.",
  1302. X                    showcell ? "en" : "dis");
  1303. X                break;
  1304. X            case 'x': case 'X':
  1305. X                Crypt = (! Crypt);
  1306. X                error ("Encryption %sabled.", Crypt? "en" : "dis");
  1307. X                break;
  1308. X            case '$':
  1309. X                if (prescale == 1.0) {
  1310. X                error ("Prescale enabled.");
  1311. X                prescale = 0.01;
  1312. X                } else {
  1313. X                prescale = 1.0;
  1314. X                error ("Prescale disabled.");
  1315. X                }
  1316. X                break;
  1317. X            case 'e': case 'E':
  1318. X                extfunc = (! extfunc);
  1319. X                error ("External functions %sabled.",
  1320. X                    extfunc? "en" : "dis");
  1321. X                break;
  1322. X            case ESC:
  1323. X            case ctl('g'):
  1324. X                --modflg;    /* negate the modflg++ */
  1325. X                break;
  1326. X            default:
  1327. X                error ("Invalid toggle command");
  1328. X                --modflg;    /* negate the modflg++ */
  1329. X            }
  1330. X            FullUpdate++;
  1331. X            modflg++;
  1332. X            break;
  1333. X
  1334. X        case ctl('u'):
  1335. X            narg = arg * 4;
  1336. X            nedistate = 1;
  1337. X            break;
  1338. X
  1339. X        case ctl('v'):    /* insert variable name */
  1340. X            if (linelim > 0)
  1341. X                ins_string(v_name(currow, curcol));
  1342. X            break;
  1343. X
  1344. X        case ctl('w'):    /* insert variable expression */
  1345. X            if (linelim > 0)  {
  1346. X            char *temp, *temp1;
  1347. X            int templim;
  1348. X
  1349. X            temp = strcpy(xmalloc((unsigned)(strlen(line)+1)),line);
  1350. X            templim = linelim;
  1351. X            editexp(currow,curcol);
  1352. X            temp1= strcpy(xmalloc((unsigned)(strlen(line)+1)),line);
  1353. X            strcpy(line, temp);
  1354. X            linelim = templim;
  1355. X            ins_string(temp1);
  1356. X            xfree(temp);
  1357. X            xfree(temp1);
  1358. X            }
  1359. X            break;
  1360. X
  1361. X        case ctl('a'):    /* insert variable value */
  1362. X            if (linelim > 0) {
  1363. X            struct ent *p = *ATBL(tbl, currow, curcol);
  1364. X            char temp[100];
  1365. X
  1366. X            if (p && p -> flags & is_valid) {
  1367. X                (void) sprintf (temp, "%.*f",
  1368. X                    precision[curcol],p -> v);
  1369. X                ins_string(temp);
  1370. X            }
  1371. X            }
  1372. X            break;
  1373. X
  1374. X        } /* End of the control char switch stmt */
  1375. X    else if (isdigit(c) && ((numeric && edistate >= 0) ||
  1376. X            (!numeric && (linelim < 0 || edistate >= 0)))) {
  1377. X        /* we got a leading number */
  1378. X        if (edistate != 0) {
  1379. X        /* First char of the count */
  1380. X        if (c == '0')      /* just a '0' goes to left col */
  1381. X            curcol = 0;
  1382. X        else {
  1383. X            nedistate = 0;
  1384. X            narg = c - '0';
  1385. X        }
  1386. X        } else {
  1387. X        /* Succeeding count chars */
  1388. X        nedistate = 0;
  1389. X        narg = arg * 10 + (c - '0');
  1390. X        }
  1391. X    } else if (linelim >= 0) {
  1392. X        /* Editing line */
  1393. X        switch(c) {
  1394. X        case ')':
  1395. X        if (showrange) {
  1396. X            showdr();
  1397. X            showrange = 0;
  1398. X            linelim = strlen (line);
  1399. X        }
  1400. X        break;
  1401. X        default:
  1402. X        break;
  1403. X        }
  1404. X        write_line(c);
  1405. X
  1406. X    } else if (!numeric && ( c == '+' || c == '-' ) ) {
  1407. X        /* increment/decrement ops */
  1408. X        register struct ent *p = *ATBL(tbl, currow, curcol);
  1409. X        if (!p)
  1410. X        continue;
  1411. X        if (p->expr && !(p->flags & is_strexpr)) {
  1412. X        error("Can't increment/decrement a formula\n");
  1413. X        continue;
  1414. X        }
  1415. X        FullUpdate++;
  1416. X        modflg++;
  1417. X        if( c == '+' )
  1418. X            p -> v += (double) arg;
  1419. X        else
  1420. X        p -> v -= (double) arg;
  1421. X    } else
  1422. X        /* switch on a normal command character */
  1423. X        switch (c) {
  1424. X        case ':':
  1425. X            break;    /* Be nice to vi users */
  1426. X
  1427. X        case '@':
  1428. X            EvalAll ();
  1429. X            changed = 0;
  1430. X            anychanged = TRUE;
  1431. X            break;
  1432. X
  1433. X        case '0': case '1': case '2': case '3': case '4':
  1434. X        case '5': case '6': case '7': case '8': case '9':
  1435. X        case '-': case '.': case '+':
  1436. X            (void) sprintf(line,"let %s = %c",
  1437. X                v_name(currow, curcol), c);
  1438. X            linelim = strlen (line);
  1439. X            insert_mode();
  1440. X            break;
  1441. X
  1442. X        case '=':
  1443. X            (void) sprintf(line,"let %s = ",
  1444. X                    v_name(currow, curcol));
  1445. X            linelim = strlen (line);
  1446. X            insert_mode();
  1447. X            break;
  1448. X
  1449. X        case '!':
  1450. X            {
  1451. X            /*
  1452. X             *  "! command"  executes command
  1453. X             *  "!"    forks a shell
  1454. X             *  "!!" repeats last command
  1455. X             */
  1456. X#ifdef VMS
  1457. X            error("Not implemented on VMS");
  1458. X#else /* VMS */
  1459. X            char *shl;
  1460. X            int pid, temp;
  1461. X            char cmd[MAXCMD];
  1462. X            static char lastcmd[MAXCMD];
  1463. X
  1464. X            if (!(shl = getenv("SHELL")))
  1465. X            shl = "/bin/sh";
  1466. X
  1467. X            deraw();
  1468. X            (void) fputs("! ", stdout);
  1469. X            (void) fflush(stdout);
  1470. X            (void) fgets(cmd, MAXCMD, stdin);
  1471. X            cmd[strlen(cmd) - 1] = '\0';    /* clobber \n */
  1472. X            if(strcmp(cmd,"!") == 0)        /* repeat? */
  1473. X                (void) strcpy(cmd, lastcmd);
  1474. X            else
  1475. X                (void) strcpy(lastcmd, cmd);
  1476. X
  1477. X            if (modflg)
  1478. X            {
  1479. X            (void) puts ("[No write since last change]");
  1480. X            (void) fflush (stdout);
  1481. X            }
  1482. X
  1483. X            if (!(pid = fork()))
  1484. X            {
  1485. X            (void) signal (SIGINT, SIG_DFL);  /* reset */
  1486. X            if(strlen(cmd))
  1487. X                (void)execl(shl,shl,"-c",cmd,(char *)0);
  1488. X            else
  1489. X                (void) execl(shl, shl, (char *)0);
  1490. X            exit(-127);
  1491. X            }
  1492. X
  1493. X            while (pid != wait(&temp));
  1494. X
  1495. X            (void) printf("Press RETURN to continue ");
  1496. X            (void)nmgetch();
  1497. X            goraw();
  1498. X#endif /* VMS */
  1499. X            break;
  1500. X            }
  1501. X
  1502. X        /*
  1503. X         * Range commands:
  1504. X         */
  1505. X
  1506. X        case '/':
  1507. X            error (
  1508. X"Range:  x:erase  v:value  c:copy  f:fill  d:define  s:show  u:undefine");
  1509. X            (void) refresh();
  1510. X
  1511. X            switch (nmgetch()) {
  1512. X            case 'c':
  1513. X            (void) sprintf(line,"copy [dest_range src_range] ");
  1514. X            linelim = strlen(line);
  1515. X            startshow();
  1516. X            insert_mode();
  1517. X            break;
  1518. X            case 'x':
  1519. X            (void) sprintf(line,"erase [range] ");
  1520. X            linelim = strlen(line);
  1521. X            startshow();
  1522. X            insert_mode();
  1523. X            break;
  1524. X            case 'v':
  1525. X            (void) sprintf(line, "value [range] ");
  1526. X            linelim = strlen(line);
  1527. X            startshow();
  1528. X            insert_mode();
  1529. X            break;
  1530. X            case 'f':
  1531. X            (void) sprintf(line,"fill [range start inc] ");
  1532. X            linelim = strlen(line);
  1533. X            startshow();
  1534. X            insert_mode();
  1535. X            break;
  1536. X            case 'd':
  1537. X            (void) sprintf(line,"define [string range] \"");
  1538. X            linelim = strlen(line);
  1539. X            startshow();
  1540. X            insert_mode();
  1541. X            modflg++;
  1542. X            break;
  1543. X            case 'u':
  1544. X            (void) sprintf(line,"undefine [range] ");
  1545. X            linelim = strlen(line);
  1546. X            insert_mode();
  1547. X            modflg++;
  1548. X            break;
  1549. X            case 's':
  1550. X            if(are_ranges())
  1551. X            {
  1552. X            FILE *f;
  1553. X            int pid;
  1554. X            char px[MAXCMD] ;
  1555. X            char *pager;
  1556. X
  1557. X            (void) strcpy(px, "| sort | ");
  1558. X            if(!(pager = getenv("PAGER")))
  1559. X                pager = DFLT_PAGER;
  1560. X            (void) strcat(px,pager);
  1561. X            f = openout(px, &pid);
  1562. X            if (!f) {
  1563. X                error("Can't open pipe to sort");
  1564. X                break;
  1565. X            }
  1566. X            list_range(f);
  1567. X            closeout(f, pid);
  1568. X            }
  1569. X            else error("No ranges defined");
  1570. X            break;
  1571. X            
  1572. X            case ESC:
  1573. X            case ctl('g'):
  1574. X            break;
  1575. X           default:
  1576. X            error("Invalid region command");
  1577. X            break;
  1578. X           }
  1579. X           break;
  1580. X
  1581. X        /*
  1582. X         * Row/column commands:
  1583. X         */
  1584. X
  1585. X        case 'i':
  1586. X        case 'a':
  1587. X        case 'd':
  1588. X        case 'p':
  1589. X        case 'v':
  1590. X        case 'z':
  1591. X        case 's':
  1592. X            {
  1593. X            register rcqual;
  1594. X
  1595. X            if (! (rcqual = get_rcqual (c))) {
  1596. X                error ("Invalid row/column command");
  1597. X                break;
  1598. X            }
  1599. X
  1600. X            error ("");    /* clear line */
  1601. X
  1602. X            if ( rcqual == ESC || rcqual == ctl('g'))
  1603. X                break;
  1604. X
  1605. X            switch (c) {
  1606. X
  1607. X            case 'i':
  1608. X                if (rcqual == 'r')    insertrow(arg);
  1609. X                else        opencol(curcol, arg);
  1610. X                break;
  1611. X
  1612. X            case 'a':
  1613. X                if (rcqual == 'r')    while (arg--) duprow();
  1614. X                else        while (arg--) dupcol();
  1615. X                break;
  1616. X
  1617. X            case 'd':
  1618. X                if (rcqual == 'r')    deleterow(arg);
  1619. X                else        closecol(curcol, arg);
  1620. X                break;
  1621. X
  1622. X            case 'p':
  1623. X                while (arg--)    pullcells(rcqual);
  1624. X                break;
  1625. X
  1626. X            case 'v':
  1627. X                if (rcqual == 'r')    rowvalueize(arg);
  1628. X                else        colvalueize(arg);
  1629. X                modflg = 1;
  1630. X                break;
  1631. X
  1632. X            case 'z':
  1633. X                if (rcqual == 'r')    hiderow(arg);
  1634. X                else        hidecol(arg);
  1635. X                break;
  1636. X
  1637. X            case 's':
  1638. X                /* special case; no repeat count */
  1639. X
  1640. X                if (rcqual == 'r')    rowshow_op();
  1641. X                else        colshow_op();
  1642. X                break;
  1643. X            }
  1644. X            break;
  1645. X            }
  1646. X
  1647. X        case '$':
  1648. X            {
  1649. X            register struct ent *p;
  1650. X
  1651. X            curcol = maxcols - 1;
  1652. X            while (!VALID_CELL(p, currow, curcol) && curcol > 0)
  1653. X            curcol--;
  1654. X            break;
  1655. X            }
  1656. X        case '#':
  1657. X            {
  1658. X            register struct ent *p;
  1659. X
  1660. X            currow = maxrows - 1;
  1661. X            while (!VALID_CELL(p, currow, curcol) && currow > 0)
  1662. X            currow--;
  1663. X            break;
  1664. X            }
  1665. X        case 'w':
  1666. X            {
  1667. X            register struct ent *p;
  1668. X
  1669. X            while (--arg>=0) {
  1670. X            do {
  1671. X                if (curcol < maxcols - 1)
  1672. X                curcol++;
  1673. X                else {
  1674. X                if (currow < maxrows - 1) {
  1675. X                    while(++currow < maxrows - 1 &&
  1676. X                        row_hidden[currow]) /* */;
  1677. X                    curcol = 0;
  1678. X                } else {
  1679. X                    error("At end of table");
  1680. X                    break;
  1681. X                }
  1682. X                }
  1683. X            } while(col_hidden[curcol] ||
  1684. X                !VALID_CELL(p, currow, curcol));
  1685. X            }
  1686. X            break;
  1687. X            }
  1688. X        case 'b':
  1689. X            {
  1690. X            register struct ent *p;
  1691. X
  1692. X            while (--arg>=0) {
  1693. X            do {
  1694. X                if (curcol) 
  1695. X                curcol--;
  1696. X                else {
  1697. X                if (currow) {
  1698. X                    while(--currow &&
  1699. X                    row_hidden[currow]) /* */;
  1700. X                    curcol = maxcols - 1;
  1701. X                } else {
  1702. X                    error ("At start of table");
  1703. X                    break;
  1704. X                }
  1705. X                }
  1706. X            } while(col_hidden[curcol] ||
  1707. X                !VALID_CELL(p, currow, curcol));
  1708. X            }
  1709. X            break;
  1710. X            }
  1711. X        case '^':
  1712. X            currow = 0;
  1713. X            break;
  1714. X        case '?':
  1715. X            help();
  1716. X            break;
  1717. X        case '"':
  1718. X            (void) sprintf (line, "label %s = \"",
  1719. X                    v_name(currow, curcol));
  1720. X            linelim = strlen (line);
  1721. X            insert_mode();
  1722. X            break;
  1723. X        case '<':
  1724. X            (void) sprintf (line, "leftstring %s = \"",
  1725. X                v_name(currow, curcol));
  1726. X            linelim = strlen (line);
  1727. X            insert_mode();
  1728. X            break;
  1729. X        case '>':
  1730. X            (void) sprintf (line, "rightstring %s = \"",
  1731. X               v_name(currow, curcol));
  1732. X            linelim = strlen (line);
  1733. X            insert_mode();
  1734. X            break;
  1735. X        case 'e':
  1736. X            editv (currow, curcol);
  1737. X            edit_mode();
  1738. X            break;
  1739. X        case 'E':
  1740. X            edits (currow, curcol);
  1741. X            edit_mode();
  1742. X            break;
  1743. X        case 'f':
  1744. X            if (arg == 1)
  1745. X            (void) sprintf (line, "format [for column] %s ",
  1746. X                coltoa(curcol));
  1747. X            else {
  1748. X            (void) sprintf(line, "format [for columns] %s:",
  1749. X                coltoa(curcol));
  1750. X            (void) sprintf(line+strlen(line), "%s ",
  1751. X                coltoa(curcol+arg-1));
  1752. X            }
  1753. X            error("Current format is %d %d",
  1754. X                fwidth[curcol],precision[curcol]);
  1755. X            linelim = strlen (line);
  1756. X            insert_mode();
  1757. X            break;
  1758. X        case 'g':
  1759. X            (void) sprintf (line, "goto [v] ");
  1760. X            linelim = strlen (line);
  1761. X            insert_mode();
  1762. X            break;
  1763. X        case 'P':
  1764. X            (void) sprintf (line, "put [\"dest\" range] \"");
  1765. X            if (*curfile)
  1766. X            error ("Default path is \"%s\"",curfile);
  1767. X            linelim = strlen (line);
  1768. X            insert_mode();
  1769. X            break;
  1770. X        case 'M':
  1771. X            (void) sprintf (line, "merge [\"source\"] \"");
  1772. X            linelim = strlen (line);
  1773. X            insert_mode();
  1774. X            break;
  1775. X        case 'R':
  1776. X            if (mdir)
  1777. X            (void) sprintf (line,"merge [\"macro_file\"] \"%s/", mdir);
  1778. X            else
  1779. X            (void) sprintf (line,"merge [\"macro_file\"] \"");
  1780. X            linelim = strlen (line);
  1781. X            insert_mode();
  1782. X            break;
  1783. X        case 'D':
  1784. X            (void) sprintf (line, "mdir [\"macro_directory\"] \"");
  1785. X            linelim = strlen (line);
  1786. X            insert_mode();
  1787. X            break;
  1788. X        case 'G':
  1789. X            (void) sprintf (line, "get [\"source\"] \"");
  1790. X            if (*curfile)
  1791. X            error ("Default file is \"%s\"",curfile);
  1792. X            linelim = strlen (line);
  1793. X            insert_mode();
  1794. X            break;
  1795. X        case 'W':
  1796. X            (void) sprintf (line, "write [\"dest\" range] \"");
  1797. X            linelim = strlen (line);
  1798. X            insert_mode();
  1799. X            break;
  1800. X        case 'S':    /* set options */
  1801. X            (void) sprintf (line, "set ");
  1802. X            error("Options: byrows, bycols, iterations=n, tblstyle=(0|tbl|latex|tex)");
  1803. X            linelim = strlen (line);
  1804. X            insert_mode();
  1805. X            break;
  1806. X        case 'T':    /* tbl output */
  1807. X            (void) sprintf (line, "tbl [\"dest\" range] \"");
  1808. X            linelim = strlen (line);
  1809. X            insert_mode();
  1810. X            break;
  1811. X        case 'x':
  1812. X            {
  1813. X            register struct ent **pp;
  1814. X            register int c1;
  1815. X
  1816. X            flush_saved();
  1817. X            if(calc_order == BYROWS) {
  1818. X            for (c1 = curcol; arg-- && c1 < maxcols; c1++) {
  1819. X            pp = ATBL(tbl, currow, c1);
  1820. X            if (*pp) {
  1821. X                free_ent(*pp);
  1822. X                *pp = (struct ent *)0;
  1823. X            }
  1824. X            }
  1825. X            }
  1826. X            else {
  1827. X            for (c1 = currow; arg-- && c1 < maxrows; c1++) {
  1828. X            pp = ATBL(tbl, c1, curcol);
  1829. X            if (*pp) {
  1830. X                free_ent(*pp);
  1831. X                *pp = (struct ent *)0;
  1832. X            }
  1833. X            }
  1834. X            }
  1835. X            sync_refs();
  1836. X            modflg++;
  1837. X            FullUpdate++;
  1838. X            }
  1839. X            break;
  1840. X        case 'Q':
  1841. X        case 'q':
  1842. X            running = 0;
  1843. X            break;
  1844. X        case 'h':
  1845. X            backcol(arg);
  1846. X            break;
  1847. X        case 'j':
  1848. X            forwrow(arg);
  1849. X            break;
  1850. X        case 'k':
  1851. X            backrow(arg);
  1852. X            break;
  1853. X        case ' ':
  1854. X        case 'l':
  1855. X            forwcol(arg);
  1856. X            break;
  1857. X        case 'm':
  1858. X            savedrow = currow;
  1859. X            savedcol = curcol;
  1860. X            break;
  1861. X        case 'c': {
  1862. X            register struct ent *p = *ATBL(tbl, savedrow, savedcol);
  1863. X            register c1;
  1864. X            register struct ent *n;
  1865. X            if (!p)
  1866. X            break;
  1867. X            FullUpdate++;
  1868. X            modflg++;
  1869. X            for (c1 = curcol; arg-- && c1 < maxcols; c1++) {
  1870. X            n = lookat (currow, c1);
  1871. X            (void) clearent(n);
  1872. X            copyent( n, p, currow - savedrow, c1 - savedcol);
  1873. X            }
  1874. X            break;
  1875. X        }
  1876. X        default:
  1877. X            if ((toascii(c)) != c)
  1878. X            error ("Weird character, decimal %d\n",
  1879. X                (int) c);
  1880. X            else
  1881. X                error ("No such command (%c)", c);
  1882. X            break;
  1883. X        }
  1884. X    edistate = nedistate;
  1885. X    arg = narg;
  1886. X    }                /* while (running) */
  1887. X    inloop = modcheck(" before exiting");
  1888. X    }                /*  while (inloop) */
  1889. X    deraw();
  1890. X    endwin();
  1891. X#ifdef VMS    /* Unit VMS "fixes" exit we should say 1 here */
  1892. X    exit(1);
  1893. X#else
  1894. X    exit(0);
  1895. X#endif
  1896. X    /*NOTREACHED*/
  1897. X}
  1898. X
  1899. Xvoid
  1900. Xstartshow()
  1901. X{
  1902. X    showrange = 1;
  1903. X    showsr = currow;
  1904. X    showsc = curcol;
  1905. X}
  1906. X
  1907. Xvoid
  1908. Xshowdr()
  1909. X{
  1910. X    int     minsr, minsc, maxsr, maxsc;
  1911. X
  1912. X    minsr = showsr < currow ? showsr : currow;
  1913. X    minsc = showsc < curcol ? showsc : curcol;
  1914. X    maxsr = showsr > currow ? showsr : currow;
  1915. X    maxsc = showsc > curcol ? showsc : curcol;
  1916. X    (void) sprintf (line+linelim,"%s", r_name(minsr, minsc, maxsr, maxsc));
  1917. X}
  1918. X
  1919. Xvoid
  1920. Xsetorder(i)
  1921. Xint i;
  1922. X{
  1923. X    if((i == BYROWS)||(i == BYCOLS))
  1924. X        calc_order = i;
  1925. X    else
  1926. X        error("Not yet implemented");
  1927. X}
  1928. X
  1929. Xvoid
  1930. Xsetauto(i)
  1931. Xint i;
  1932. X{
  1933. X    autocalc = i;
  1934. X}
  1935. X
  1936. X
  1937. X#ifdef VMS
  1938. X
  1939. Xgoraw()
  1940. X{
  1941. X    VMS_read_raw = 1;
  1942. X    FullUpdate++;
  1943. X}
  1944. X
  1945. Xderaw()
  1946. X{
  1947. X    (void) move (LINES - 1, 0);
  1948. X    (void) clrtoeol();
  1949. X    (void) refresh();
  1950. X    VMS_read_raw = 0;
  1951. X}
  1952. X
  1953. X#else /* VMS */
  1954. Xvoid
  1955. Xgoraw()
  1956. X{
  1957. X#if SYSV2 || SYSV3
  1958. X    fixterm();
  1959. X#else /* SYSV2 || SYSV3 */
  1960. X    cbreak();
  1961. X    nonl();
  1962. X    noecho ();
  1963. X#endif /* SYSV2 || SYSV3 */
  1964. X    kbd_again();
  1965. X    (void) clear();
  1966. X    FullUpdate++;
  1967. X}
  1968. X
  1969. Xvoid
  1970. Xderaw()
  1971. X{
  1972. X    (void) move (LINES - 1, 0);
  1973. X    (void) clrtoeol();
  1974. X    (void) refresh();
  1975. X#if SYSV2 || SYSV3
  1976. X    resetterm();
  1977. X#else
  1978. X    nocbreak();
  1979. X    nl();
  1980. X    echo();
  1981. X#endif
  1982. X    resetkbd();
  1983. X}
  1984. X
  1985. X#endif /* VMS */
  1986. X
  1987. Xvoid
  1988. Xsignals()
  1989. X{
  1990. X#ifdef SIGVOID
  1991. X    void quit();
  1992. X    void time_out();
  1993. X    void dump_me();
  1994. X#else
  1995. X    int quit();
  1996. X    int time_out();
  1997. X    int dump_me();
  1998. X#endif
  1999. X
  2000. X    (void) signal(SIGINT, SIG_IGN);
  2001. X    (void) signal(SIGQUIT, dump_me);
  2002. X    (void) signal(SIGPIPE, quit);
  2003. X    (void) signal(SIGTERM, quit);
  2004. X    (void) signal(SIGALRM, time_out);
  2005. X    (void) signal(SIGFPE, quit);
  2006. X    (void) signal(SIGBUS, quit);
  2007. X}
  2008. X
  2009. X#ifdef SIGVOID
  2010. Xvoid
  2011. X#endif
  2012. Xquit()
  2013. X{
  2014. X    diesave();
  2015. X    deraw();
  2016. X    resetkbd();
  2017. X    endwin();
  2018. X    exit(1);
  2019. X}
  2020. X
  2021. X#ifdef SIGVOID
  2022. Xvoid
  2023. X#endif
  2024. Xdump_me()
  2025. X{
  2026. X    diesave();
  2027. X    deraw();
  2028. X    abort();
  2029. X}
  2030. X
  2031. X/* try to save the current spreadsheet if we can */
  2032. Xdiesave()
  2033. X{   char    path[PATHLEN];
  2034. X    if (modcheck(" before Spreadsheet dies") == 1)
  2035. X    {    sprintf(path, "~/SC.SAVE");
  2036. X    if (writefile(path, 0, 0, maxrow, maxcol) < 0)
  2037. X        if (writefile("/tmp/SC.SAVE", 0, 0, maxrow, maxcol) < 0)
  2038. X        error("Couldn't save current spreadsheet, Sorry");
  2039. X    }
  2040. X}
  2041. X
  2042. Xint
  2043. Xmodcheck(endstr)
  2044. Xchar *endstr;
  2045. X{
  2046. X    if (modflg && curfile[0]) {
  2047. X    int    yn_ans;
  2048. X    char    lin[100];
  2049. X
  2050. X    (void) sprintf (lin,"File \"%s\" is modified, save%s? ",curfile,endstr);
  2051. X    if ((yn_ans = yn_ask(lin)) < 0)
  2052. X        return(1);
  2053. X    else
  2054. X    if (yn_ans == 1)
  2055. X    {    if (writefile(curfile, 0, 0, maxrow, maxcol) < 0)
  2056. X         return (1);
  2057. X    }
  2058. X    } else if (modflg) {
  2059. X    int    yn_ans;
  2060. X
  2061. X    if ((yn_ans = yn_ask("Do you want a chance to save the data? ")) < 0)
  2062. X        return(1);
  2063. X    else
  2064. X        return(yn_ans);
  2065. X    }
  2066. X    return(0);
  2067. X}
  2068. END_OF_FILE
  2069.   if test 33828 -ne `wc -c <'sc.c'`; then
  2070.     echo shar: \"'sc.c'\" unpacked with wrong size!
  2071.   fi
  2072.   # end of 'sc.c'
  2073. fi
  2074. echo shar: End of archive 3 \(of 6\).
  2075. cp /dev/null ark3isdone
  2076. MISSING=""
  2077. for I in 1 2 3 4 5 6 ; do
  2078.     if test ! -f ark${I}isdone ; then
  2079.     MISSING="${MISSING} ${I}"
  2080.     fi
  2081. done
  2082. if test "${MISSING}" = "" ; then
  2083.     echo You have unpacked all 6 archives.
  2084.     rm -f ark[1-9]isdone
  2085. else
  2086.     echo You still must unpack the following archives:
  2087.     echo "        " ${MISSING}
  2088. fi
  2089. exit 0
  2090. exit 0 # Just in case...
  2091.